package cmtests;

import java.util.Date;

import com.ibm.mm.sdk.common.DKConstant;
import com.ibm.mm.sdk.common.DKConstantICM;
import com.ibm.mm.sdk.common.DKDDO;
import com.ibm.mm.sdk.common.DKException;
import com.ibm.mm.sdk.common.DKLobICM;
import com.ibm.mm.sdk.common.DKParts;
import com.ibm.mm.sdk.common.DKTextICM;
import com.ibm.mm.sdk.server.DKDatastoreICM;

public class Test2 {
	static String database = "serverged30";
	static String userName = "icmadmin";
	static String password = "icmadmin";
	static String schema = "SCHEMA=" + "ICMADMIN";


	public static void main(String[] args) {
		// TODO Auto-generated method stub

		DKDatastoreICM dsICM;
		try {
			dsICM = new DKDatastoreICM();
			dsICM.connect(database, userName, password, schema);
			DKDDO document = dsICM.createDDO("WASSIL",
					DKConstant.DK_CM_DOCUMENT);

			DKTextICM base = (DKTextICM) dsICM.createDDO("ICMBASETEXT",
					DKConstantICM.DK_ICM_SEMANTIC_TYPE_BASETEXT);

			base.setContentFromClientFile("C:\\Users\\stage1\\Desktop\\CPT_DB2\\test.txt");
			base.setMimeType("text/plain");
			// DKLobICM base = (DKLobICM) dsICM.createDDO("ICMBASE",
			// DKConstant.DK_CM_ITEM);
			//
			// base.setContentFromClientFile("C:\\Users\\stage1\\Desktop\\CPT_DB2\\1X.JPEG");
			// base.setMimeType("image/tiff");

			DKParts dkParts = (DKParts) document.getData(document.dataId(
					DKConstant.DK_CM_NAMESPACE_ATTR, DKConstant.DK_CM_DKPARTS));

			dkParts.addElement(base);

			document.setData(document.dataId(DKConstant.DK_CM_NAMESPACE_ATTR,
					"NomDocument"), "testdoc2");
			document.setData(document.dataId(DKConstant.DK_CM_NAMESPACE_ATTR,
					"NumDocument"), "4404");
			document.setData(document.dataId(DKConstant.DK_CM_NAMESPACE_ATTR,
					"dateinsert"), new java.sql.Date(2014, 5, 5));

			document.add();

			dsICM.disconnect();
			dsICM.destroy();

		} catch (DKException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("-------------" + e.getMessage());
			System.out.println("-------------" + e.getErrorId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
